﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TestApp
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            comboBox1.SelectedIndex = 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string binStr = textBox1.Text;
            bool isBin = true;
            if (binStr!="")
            {
                for (int i = 0; i < binStr.Length; i++)
                {
                    if (binStr[i].ToString()!="1" && binStr[i].ToString()!="0")
                    {
                        isBin = false;
                        break;
                    }
                }

                // convert to long
                
                if (isBin)
                {
                    long l = Convert.ToInt64(binStr, 2);
                    if (comboBox1.SelectedIndex==0)
                    {
                        textBox2.Text = Convert.ToString(l, 8);
                    }
                    else if (comboBox1.SelectedIndex==1)
                    {
                        textBox2.Text = Convert.ToString(l, 10);
                    }
                    else
                    {
                        textBox2.Text = Convert.ToString(l, 16).ToUpper();
                    }
                    
                }
                else
                {
                    textBox2.Text = "Not a binary!";
                }
            }
        }
    }
}
